import yaml

from msg import Message
from globals import globalCacheMessageList
from SendToNeighbours import send_message_to_neighbors
from SendMessageFrontEnd import send_message_front_end


def is_message_cached (mp, message):

    print " Code in isMessageCached"
    global globalCacheMessageList
    toUser = message.data
    returnFEMessageList = []

    for item in globalCacheMessageList :

        #print item
        if item.toUserName == toUser :
            returnFEMessageList.append(item)
            ifSend = True

    send_message_to_neighbors (mp, message)

    data = yaml.dump(returnFEMessageList)
    send_message_front_end (mp, None, message.broadcastSource, data)

    return
